package conf

// 所有的配置文件对应的对象，私有化

type Conf struct {
	Mysql
	log
	server
}

// 日志的配置对象，私有化

type log struct {
	Level string
}

// server 的配置对象，私有化

type server struct {
	ListenAddress string
	Port          uint
}

// 数据库的配置对象

type Mysql struct {
	User     string
	Password string
	Host     string
	Port     uint
	Database string
}

//var globalConfig = &Conf{}

func NewLog() *log {
	return &log{
		Level: "info",
	}
}

func NewMysql() *Mysql {
	return &Mysql{
		User:     "root",
		Password: "123456",
		Host:     "localhost",
		Port:     3306,
		Database: "user",
	}
}

func NewServer() *server {
	return &server{
		ListenAddress: "localhost",
		Port:          8080,
	}
}

//默认的构造函数

func NewDefaultConf() *Conf {

	return &Conf{
		server: *NewServer(),
		Mysql:  *NewMysql(),
		log:    *NewLog(),
	}
}

//空的构造函数

func (c *Conf) Set(conf *Conf) {
	c.Mysql = conf.Mysql
	c.log = conf.log
	c.server = conf.server

}

func (c *Conf) Get() *Conf {
	return &Conf{
		Mysql:  c.Mysql,
		log:    c.log,
		server: c.server,
	}
}
